var Tree = function () {
	var branches = [];

	var timer;

	this.stat = {
		fork: 0,

		length: 0,
	};

	this.addBranch = function (b) {
		branches.push(b);
	};

	this.removeBranch = function (b) {
		for (var i = 0; i < branches.length; i++) {
			if (branches[i] === b) {
				branches.splice(i, 1);

				return;
			}
		}
	};

	this.render = function (fn) {
		var that = this;

		timer = setInterval(function () {
			fn.apply(that, arguments);

			if (branches.length > 0) {
				for (var i = 0; i < branches.length; i++) {
					branches[i].grow();
				}
			} else {
				//clearInterval(timer);
			}
		}, 1000 / 30);
	};

	this.init = function (ctx) {
		this.ctx = ctx;
	};

	this.abort = function () {
		branches = [];

		this.stat = {
			fork: 0,

			length: 0,
		};
	};
};

export default Tree;
